﻿@model System.Collections.Generic.List<Test.DataAccess.POCO.Permission>
@*Express.DataAccess.POCO.Permission*@
@section Styles{
    <style type="text/css">
    </style>
}
@section Scripts{
    <script type="text/javascript">
        $(function () {
            $('#permissionList').nestable({
                maxDepth: 2
            }).on('change', function (e) {
                console.log($(e.target).nestable('serialize'));
            });

            window.getConfirmAttachData = function () {
                return { "orderInfo": JSON.stringify($("#permissionList").nestable('serialize')) };
            }


            Toolbox.Notifier.info("提示：请小心操作本页面");
        })
    </script>
}

@helper OrderedList(System.Collections.Generic.List<Test.DataAccess.POCO.Permission> permissions)
{
    <ol class="dd-list">
        @foreach (var permission in permissions.OrderBy(p => p.Order))
        {
            <li class="dd-item dd3-item" data-id="@permission.Id">
                <div class="dd-handle dd3-handle">
                </div>
                <div class="dd3-content">
                    @(permission.PermissionName)@(permission.IsMenu ? "" : "（非菜单）")
                    &nbsp;&nbsp;&nbsp;
                    @permission.Description
                    <a data-confirm-text="确定要删除吗？" data-confirm-button="确定" data-cancel-button="取消"
                       data-confirmed-url="@Url.Action("DeletePermission", "Account", new { id = permission.Id })"
                       class="btn btn-danger btn-xs js-table-ajax-confirm-button pull-right">
                        <i class="fa fa-trash-o"></i>删除
                    </a>
                    <a href="@Url.Action("CreateOrEditPermission","Account",new { id = permission.Id })" class="pull-right btn btn-info btn-xs"><i class="fa fa-edit"></i>编辑</a>

                </div>
                @if (permission.Chindren.Count() > 0)
                {
                    @OrderedList(permission.Chindren.ToList())
                }
            </li>
        }
    </ol>
}
<!-- BEGIN TABLE PORTLET -->
<div class="portlet box light-grey">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-reorder"></i>权限列表
        </div>
    </div>
    <div class="portlet-body">
        <div class="table-toolbar">
            <a data-confirmed-url="@Url.Action("SavePermissionOrder")"
               data-confirm-text="确定要保存上下级关系和顺序吗？" data-confirm-button="确定" data-cancel-button="取消"
               class="btn btn-success js-table-ajax-confirm-button">
                保存<i class="fa fa-save"></i>
            </a>
            <a href="@Url.Action("CreateOrEditPermission")" class="btn btn-success">
                添加 <i class="fa fa-plus"></i>
            </a>
        </div>
        <div class="dd" id="permissionList">
            @OrderedList(Model)
        </div>
    </div>
</div>
<!-- BEGIN TABLE PORTLET -->
